/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.home.dao;

import com.home.common.utils.HibernateUtil;
import com.home.mapping.Account;
import com.home.mapping.AttributeGroup;
import com.home.mapping.ScorecardType;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author vi
 */
public class ScorecardTypeDao extends BaseDao{
    public ScorecardType findScorecardType(Integer idScorecardType) {
        ScorecardType type = new ScorecardType();
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            Criteria criteria = session.createCriteria(ScorecardType.class);
            criteria.add(Restrictions.eq("idScorecardType",idScorecardType));           
            
            List result = criteria.list();
            if (result.size() > 0) {
                type = (ScorecardType)result.get(0);
            }
           
            Hibernate.initialize(type.getAttributeGroups());
            for (Object obj : type.getAttributeGroups()) {
                AttributeGroup ag = (AttributeGroup)obj;
                Hibernate.initialize(ag.getAttributes());
            }
        } catch (Exception e) {
        } finally {
            session.close();
        }
        return type;
    }
}
